package com.microHR.hr.service.impl;

import com.microHR.hr.mapper.DepartmentMapper;
import com.microHR.hr.model.Department;
import com.microHR.hr.model.DepartmentExample;
import com.microHR.hr.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    DepartmentMapper departmentMapper;

    @Override
    public List<Department> getAllDepartments() {
        return departmentMapper.getAllDepartmentsByParentId(-1);
    }

    @Override
    public List<Department> getAllDepartmentsWithOutChildren() {
        DepartmentExample example = new DepartmentExample();
        return departmentMapper.selectByExample(example);
    }

    @Override
    public void addDep(Department dep) {
        dep.setEnabled( true);
        departmentMapper.addDep(dep);
    }

    @Override
    public void deleteDepById(Department dep) {
        departmentMapper.deleteDepById(dep);
    }


}
